**************************************************************************************************************************************************
****************************** Wealth-Income Ratios in Free Market Capitalism: Switzerland, 1900-2020 ********************************************
**************************************************************************************************************************************************

clear all
set more off
set scheme s1color  
cap set scheme mygraphs

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: January, 25 2023

*** set this path to the current directory
*** global mypath "C:\Users\EBaselgia\Dropbox\WIR_project\Publication_process\replication"

*** EXTENSION C: CROSS-COUNTRY EVIDENCE ON WIR AND HOUSING PRICES ***


* REGRESS WIR ON STOCK PRICES AND REAL ESTATE PRICES*
/* countries: CH DE FR GB IT SE US AU CA ES JP NO
	indices: OECD nominal Houseprice index (deflated with CPI), OECD Shareprice index (deflated with CPI), MSCI world index (deflated with CPI)
*/

* * * READ DATA * * * 
cd "$mypath/final_data/"
use "house_price_final_data.dta", clear
cd "$mypath/output/extension_C/"

drop if year<1970
drop if year>2019

**** rename all variables to capital country codes letters to create figures
foreach var in pWIR houseP_real_cpi shareP_real_cpi nni_T_R{

	rename au_`var' AU_`var'
	rename ca_`var' CA_`var'
	rename ch_`var' CH_`var'
	rename de_`var' DE_`var'
	rename es_`var' ES_`var'
	rename fr_`var' FR_`var'
	rename gb_`var' GB_`var'
	rename it_`var' IT_`var'
	rename jp_`var' JP_`var'
	rename no_`var' NO_`var'
	rename se_`var' SE_`var'
	rename us_`var' US_`var'
}


tsset year

** gen growth rates
foreach var in CH_pWIR DE_pWIR FR_pWIR GB_pWIR IT_pWIR SE_pWIR US_pWIR AU_pWIR CA_pWIR ES_pWIR JP_pWIR NO_pWIR ///
 AU_houseP_real_cpi CA_houseP_real_cpi CH_houseP_real_cpi DE_houseP_real_cpi ES_houseP_real_cpi FR_houseP_real_cpi ////
 GB_houseP_real_cpi IT_houseP_real_cpi JP_houseP_real_cpi NO_houseP_real_cpi SE_houseP_real_cpi US_houseP_real_cpi ////
 AU_shareP_real_cpi CA_shareP_real_cpi CH_shareP_real_cpi DE_shareP_real_cpi ES_shareP_real_cpi FR_shareP_real_cpi ///
 GB_shareP_real_cpi IT_shareP_real_cpi JP_shareP_real_cpi NO_shareP_real_cpi SE_shareP_real_cpi US_shareP_real_cpi ///
  MSCI_real_cpi{
	gen `var'_dif = (D.`var'/L.`var')*100
}





foreach var in CH DE FR GB IT SE US AU CA ES JP NO{
	
	drop `var'_nni_T_R
	label var `var'_pWIR_dif "Wealth-Income ratio, `var' (annual change in %)"
	label var `var'_houseP_real_cpi_dif "real house price index, `var' (annual change in %)"
	label var `var'_shareP_real_cpi_dif "real share price index, `var' (annual change in %)"
	label var `var'_shareP_real_cpi_dif "real share price index, `var' (annual change in %)"
} 
 
 label var MSCI_real_cpi_dif "MSCI world index real (annual change in %)"
 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * REGRESSIONS * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
foreach country in CH DE SE IT FR US AU CA ES GB JP NO{
display "this is country `country'"
tab year if `country'_pWIR_dif !=. & `country'_houseP_real_cpi_dif !=.
}



// regressions in growth rates
local a "CH DE SE IT FR US AU CA ES GB JP NO"
local i = 0
foreach country in CH DE SE IT FR US AU CA ES GB JP NO{
local i = `i' + 1
local CTRY : word `i' of `a'
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', only housing"	
reg `country'_pWIR_dif `country'_houseP_real_cpi_dif
estimates store m1_`country', title("(1)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1960(5)2020, grid) yline(0) name(resid_`country'_housing, replace)
	
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', only stock"	
reg `country'_pWIR_dif `country'_shareP_real_cpi_dif
 estimates store m2_`country', title("(2)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1960(5)2020, grid) yline(0) name(resid_`country'_shares, replace)

	
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', housing and stock"
reg `country'_pWIR_dif `country'_houseP_real_cpi_dif `country'_shareP_real_cpi_dif
 estimates store m3_`country', title("(3)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1960(5)2020, grid) yline(0) name(resid_`country', replace)
	
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', housing, stock and MSCI"
reg `country'_pWIR_dif `country'_houseP_real_cpi_dif `country'_shareP_real_cpi_dif MSCI_real_cpi_dif
 estimates store m4_`country', title("(4)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1960(5)2020, grid) yline(0) name(resid_`country'_MSCI, replace)
}





* STORE REGRESSION TABLES country by country as in tex format

local a "Switzerland Germany Sweden Italy France USA Australia Canada Spain United-Kingdom Japan Norway"
local i = 0
foreach country in CH DE SE IT FR US AU CA ES GB JP NO{
local i = `i' + 1
local CTRY : word `i' of `a'

cap rm reg_real_`country'.tex
estout m1_`country' m2_`country' m3_`country' m4_`country' using RR_reg_real_`country'.tex ///
, style(tex) starlevels(* 0.10 ** 0.05 *** 0.010) varlabels(`country'_houseP_real_cpi_dif "House prices" `country'_shareP_real_cpi_dif "Share prices" MSCI_real_cpi_dif "MSCI world" _cons Constant)  ///
append  stats(r2_a N, fmt(%9.3f %9.0g) labels("\rule{0pt}{1.6em}Adj. R$^2$" "Obs.")) cells( "b(star fmt(2)) se(fmt(2) par)") ///
/*title("`CTRY' & & & & \\")*/  mlabels(none)  collabels(none)
}







* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* * * * * * * * ** * * * * REGRESSIONS  post 1990 * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
estimates clear
drop resid_CH resid_FR resid_US resid_AU resid_CA resid_ES resid_GB resid_JP resid_NO resid_SE resid_IT resid_DE

drop if year <1990
drop if year>2019
tsset year



foreach country in CH DE SE IT FR US AU CA ES GB JP NO{
display "this is country `country'"
tab year if `country'_pWIR_dif !=. & `country'_houseP_real_cpi_dif !=.
}


// regressions in growth rates
local a "CH DE SE IT FR US AU CA ES GB JP NO"
local i = 0
foreach country in CH DE SE IT FR US AU CA ES GB JP NO{
local i = `i' + 1
local CTRY : word `i' of `a'
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', only housing"	
reg `country'_pWIR_dif `country'_houseP_real_cpi_dif
estimates store m1_`country', title("(1)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1990(5)2020, grid) yline(0) name(resid_`country'_housing, replace)
	
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', only stock"	
reg `country'_pWIR_dif `country'_shareP_real_cpi_dif
estimates store m2_`country', title("(2)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1990(5)2020, grid) yline(0) name(resid_`country'_shares, replace)
	
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', housing and stock"
reg `country'_pWIR_dif `country'_houseP_real_cpi_dif `country'_shareP_real_cpi_dif
estimates store m3_`country', title("(3)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1990(5)2020, grid) yline(0) name(resid_`country', replace)
	
	
	
display _newline(2)
display "REGRESSION RESULTS FOR `CTRY', housing, stock and MSCI"
reg `country'_pWIR_dif `country'_houseP_real_cpi_dif `country'_shareP_real_cpi_dif MSCI_real_cpi_dif
estimates store m4_`country', title("(4)")
	// residuals
	cap drop resid_`country'
	predict double resid_`country', residuals
	label var resid_`country' "Residuals (`CTRY')"
	**tw (connect resid_`country' year), ylab(, grid) xlab(1990(5)2020, grid) yline(0) name(resid_`country'_MSCI, replace)
}




* STORE REGRESSION TABLES country by country as in tex format

local a "Switzerland Germany Sweden Italy France USA Australia Canada Spain United-Kingdom Japan Norway"
local i = 0
foreach country in CH DE SE IT FR US AU CA ES GB JP NO{
local i = `i' + 1
local CTRY : word `i' of `a'

cap rm RR_reg_real_zpost1990_`country'.tex
estout m1_`country' m2_`country' m3_`country' m4_`country' using RR_reg_real_zpost1990_`country'.tex ///
, style(tex) starlevels(* 0.10 ** 0.05 *** 0.010) varlabels(`country'_houseP_real_cpi_dif "House prices" `country'_shareP_real_cpi_dif "Share prices" MSCI_real_cpi_dif "MSCI world" _cons Constant)  ///
append  stats(r2_a N, fmt(%9.3f %9.0g) labels("\rule{0pt}{1.6em}Adj. R$^2$" "Obs.")) cells( "b(star fmt(2)) se(fmt(2) par)") ///
/*title("`CTRY' & & & & \\")*/  mlabels(none)  collabels(none)
}


clear all
cd "$mypath/"
